<template>
  <div class="app-container">
    <div class="filter-container">
      <el-row>
        <el-radio-group v-model="listQuery.fileRange" size="medium" fill="#FFBA00" @change="fileRangeRadioChanged">
          <el-radio-button label="order">设备审批单</el-radio-button>
          <el-radio-button label="supplier">供应商</el-radio-button>
          <el-radio-button label="contract">合同</el-radio-button>
        </el-radio-group>
      </el-row>
      <el-row style="margin-top: 20px;">
        <el-input v-show="listQuery.fileRange === 'order'" v-model="listQuery.orderCode" placeholder="审批单编号" style="width: 200px;" class="filter-item" @keyup.enter.native="btnQuery" />
        <el-input v-show="listQuery.fileRange === 'supplier'" v-model="listQuery.supplierName" placeholder="供应商名称" style="width: 200px;" class="filter-item" @keyup.enter.native="btnQuery" />
        <el-input v-show="listQuery.fileRange === 'contract'" v-model="listQuery.contractCode" placeholder="合同编号" style="width: 200px;" class="filter-item" @keyup.enter.native="btnQuery" />
        <el-input v-model="listQuery.fileName" placeholder="文件名称" style="width: 200px;" class="filter-item" @keyup.enter.native="btnQuery" />
        <el-input v-model="listQuery.fileType" placeholder="文件类型" style="width: 200px;" class="filter-item" @keyup.enter.native="btnQuery" />
        <el-dropdown split-button type="primary" class="filter-item" @click="btnQuery">
          <i class="el-icon-search el-icon--left" />查询
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-zoom-out" @click.native="btnReset">重置</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <!--<el-button-group>-->
          <!--<el-button v-permission="'purchase:file:save'" icon="el-icon-plus" type="primary" class="filter-item" @click="addFileView()">新增</el-button>-->
        <!--</el-button-group>-->
      </el-row>
    </div>
    <file-list
      ref="files"
      :query-file-param="listQuery"
      :show-page="true"
      :show-col="showCol"
      :show-add="false"
    />
  </div>
</template>

<script>
import fileList from '@/views/purchase/file/components/fileList'

export default {
  name: 'PurchaseFile',
  components: { fileList },
  data() {
    return {
      dicts: [],
      records: null,
      selectedRecords: [],
      total: 0,
      listQuery: {
        fileRange: 'order',
        orderCode: undefined,
        supplierName: undefined,
        contractCode: undefined,
        fileName: undefined,
        fileType: undefined
      },
      showCol: ['orderCode'],
      temp: {
        id: undefined,
        orderId: '',
        contractId: '',
        projectId: '',
        supplierId: '',
        fileName: '',
        fileType: '',
        fileOriginalName: '',
        fileSize: '',
        filePath: '',
        fileComment: ''
      }
    }
  },
  beforeCreate() {

  },
  created() {
  },
  methods: {
    fileRangeRadioChanged() {
      if (this.listQuery.fileRange === 'order') {
        this.showCol = ['orderCode']
        Object.assign(this.listQuery, {
          supplierName: undefined,
          contractCode: undefined
        })
      } else if (this.listQuery.fileRange === 'supplier') {
        this.showCol = ['supplierName']
        Object.assign(this.listQuery, {
          orderCode: undefined,
          contractCode: undefined
        })
      } else if (this.listQuery.fileRange === 'contract') {
        this.showCol = ['contractCode']
        Object.assign(this.listQuery, {
          orderCode: undefined,
          supplierName: undefined
        })
      }
      this.btnQuery()
    },
    btnQuery() {
      this.$refs.files.getlistFile()
    },
    btnReset() {
      Object.assign(this.listQuery, {
        orderCode: undefined,
        supplierName: undefined,
        contractCode: undefined,
        fileName: undefined,
        fileType: undefined
      })
      this.$refs.files.getlistFile()
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        orderId: '',
        contractId: '',
        projectId: '',
        supplierId: '',
        fileName: '',
        fileType: '',
        fileOriginalName: '',
        fileSize: '',
        filePath: '',
        fileComment: ''
      }
    }
  }
}
</script>
